package whu.cn.whushare.ui.common;

import android.app.Activity;
import android.view.View;

import whu.cn.whushare.ui.main.MyTabFavoriteActivity;
import whu.cn.whushare.ui.main.MyTabRelationActivity;

/**
 * 文件名：MyFavoriteReShowFragment
 * 描 述：
 * 作 者：胡平平
 * 时 间：2014/12/27
 */
public class MyFavoriteReShowFragment extends BaseFragment{
    private MyTabFavoriteActivity myTabFavoriteActivity;

    @Override
    //当MyFavoriteReShowFragment被添加到非MyTabFavoriteActivity实例时抛出异常
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        if (activity instanceof MyTabFavoriteActivity)
            myTabFavoriteActivity = (MyTabFavoriteActivity) activity;
        else
            throw new IllegalArgumentException("fragment used in wrong activity");
    }

    /**
     * 获得顶部菜单条：先初始化TopBar，并为返回键设置事件监听器，然后返回该TopBar
     * @param root - 父控件
     * @return view - 返回当前TopBar
     */
    protected View getTopBar(View root, int topId) {
        View view = super.initTopBar(root, topId);
        mTopBar.goBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                goBack( myTabFavoriteActivity);
            }
        });
        return view;
    }

    /**
     * 获得不带返回按钮的顶部菜单条
     * @param root - 父控件
     * @return view - 返回当前TopBar
     */
    protected View getTopBarWithoutBack(View root, int topId) {
        View view = super.initTopBar(root, topId);
        mTopBar.goBack.setVisibility(View.GONE);
        return view;
    }

    public void onReShow(MyTabFavoriteActivity myTabFavoriteActivity) {
    }

    public boolean goBack(MyTabFavoriteActivity myTabFavoriteActivity) {
        myTabFavoriteActivity.goBack();
        return false;
    }
}
